<?php require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
	MYTCONN();
	//================ FORMS ===================
	$MDDC = 'RD';
	if (isset($_GET['OBJCTCL'])) {
		$OBJCTCL = $_GET['OBJCTCL'];
	}
	if (isset($_GET['OBJCTDC'])) {
		$OBJCTDC = $_GET['OBJCTDC'];
	}
	if (isset($_GET['CID'])) {
		$OBJCTCL = $_GET['CID'];
	}
	if (isset($_POST['OBJCTCL'])) {
		$OBJCTCL = $_POST['OBJCTCL'];
	}
	if (isset($_POST['OBJCTDC'])) {
		$OBJCTDC = $_POST['OBJCTDC'];
	}

	if (!isset($OBJCTDC)) {
			$MDDC = 'ED';
		$VWDCDT = 1;
		$Document[0] = 1;
		$OBJCTDC = 0;
		$DCVARS = $GLOBALS['MYT']->db_array("DESCRIBE hd_documentos");
		for ($v = 1; $v <= $DCVARS[0]; $v++) {
			$DCVAR = $DCVARS[$v]['Field'];
			$Document[1][$DCVAR] = '';
			$Document[1]['tdc_Validacion'] = 0;
		}
		$SESSOFLABEL = $GLOBALS['MYT']->db_array("SELECT name FROM systemoffice.main_offices
		WHERE ref = {$_SESSION[$SESSOF]}");
		$Document[1]['DC_OFFICE'] = $SESSOFLABEL[1]['name'];
	} else {
	if (isset($_POST['MDDCED'])) {
			$MDDC = 'ED';
	}
		$Document = $GLOBALS['MYT']->db_array("SELECT
				dtd_ID,
				dtd_Numero,
				dtd_Emisor,
				dtd_Status,
				dtd_Tipo,
				DC_OFFICE,
				DATE(dtd_FechaEmision) AS dtd_FechaEmision,
				DATE(dtd_FechaCaducidad) AS dtd_FechaCaducidad,
				tdc_Validacion,
				dtd_Fecha,
				CliOffice
			FROM hd_documentos
				INNER JOIN hd_documentostipos ON tdc_ID = dtd_Tipo
				INNER JOIN clientes ON CliNumero = dtd_Cliente
			WHERE dtd_ID = {$OBJCTDC}");
		$SESSOFLABEL = $GLOBALS['MYT']->db_array("SELECT name FROM systemoffice.main_offices
		WHERE ref = {$Document[1]['DC_OFFICE']}");
		if (isset($SESSOFLABEL[1])) {
		$Document[1]['DC_OFFICE'] = $SESSOFLABEL[1]['name'];
		} else {
		$Document[1]['DC_OFFICE'] = '';
		}
	}
	for ($dc = 1; $dc <= $Document[0]; $dc++) {
	mn_field('hidden','ED','OBJCTDC',$OBJCTDC,'0','','False','');
	mn_field('hidden','ED','tdc_Validacion',$Document[$dc]['tdc_Validacion'],'','','False','');
?>
<table width="100%"  border="0" cellpadding="3" cellspacing="2" bgcolor="#E5E5E5">
  <tr>
    <td colspan="6">
	<table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#F4F4F4">
        <tr>
          <td width="30%"><strong>Dados do Documento (<?php mn_field('hidden',$MDDC,'',$OBJCTDC,'0','','False',''); ?>)</strong></td>
          <td><?php
	if ($MDDC == 'RD' && $Document[$dc]['CliOffice'] == $_SESSION[$SESSCD] && $Document[$dc]['dtd_Status'] == 2) {
	mn_field('button','ED','MDDCED','Modificar','12','12','False','SUBMIT"
	onClick="document.ClientProperties.action=\'_response/call.php?get=Operative/view/viewsenderdocumentattch\';
	subform(\'ClientProperties\',\'NWDC\');');
	} ?></td>
          <td>Arquivado em:
          <?php
		  mn_field('text',$MDDC,'DC_OFFICE',$Document[$dc]['DC_OFFICE'],'0','20','False','" readonly="');
		  echo ' (Data: '.$Document[$dc]['dtd_Fecha'].')';?></td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td width="88" height="22">Tipo:</td>
    <td width="160">
	<?php
	$DCType = "SELECT tdc_Id AS ID, tdc_Tipo AS NAME FROM hd_documentostipos WHERE
		(Country_ID = (SELECT ClPais FROM clientes WHERE CliNumero = {$OBJCTCL})
		OR Country_ID = (SELECT CliNacionalidad FROM clientes WHERE CliNumero = {$OBJCTCL})
		OR Country_ID = (SELECT CliRes1 FROM clientes WHERE CliNumero = {$OBJCTCL})
		OR Country_ID = (SELECT CliRes2 FROM clientes WHERE CliNumero = {$OBJCTCL})
		OR Country_ID IN ({$__sys['Country']},0))
		AND tdc_Map LIKE '___1_'
		AND tdc_Activo = 1";
	if ($MDDC == 'RD') {
	$DCRDType = $GLOBALS['MYT']->db_array("SELECT tdc_Id AS ID, tdc_Tipo AS NAME FROM hd_documentostipos WHERE tdc_Id = {$Document[$dc]['dtd_Tipo']}");
	echo $DCRDType[1]['NAME'];
	}
	mn_field('select',$MDDC,'dtd_Tipos',$Document[$dc]['dtd_Tipo'],$DCType,'','False','"
	onchange="document.ClientProperties.action=\''.$GLOBALS['URL'].'Modules/CLDJ49SJ/elem_doctype.mex\';
	subform(\'ClientProperties\',\'DocType_Props\');');?></td>
    <td width="99">Data Emissão: </td>
    <td width="129"><?php echo mn_field('date',$MDDC,'dtd_FechaEmision',$Document[$dc]['dtd_FechaEmision'],'ClientProperties','8','False','');?></td>
    <td colspan="2">
    <div id="DocType_Props"></div></td>
  </tr>
  <tr>
    <td>N&uacute;mero:</td>
    <td><?php
	mn_field('text',$MDDC,'dtd_Numero',$Document[$dc]['dtd_Numero'],'16','16','False','');?></td>
    <td>      <div align="left">Caducidade:

    </div></td>
    <td><?php echo mn_field('date',$MDDC,'dtd_FechaCaducidad',$Document[$dc]['dtd_FechaCaducidad'],'ClientProperties','8','False','');?></td>
    <td width="372">Orgão Expedidor :
    <?php echo mn_field('text',$MDDC,'dtd_Emisor',$Document[$dc]['dtd_Emisor'],'30','16','False','');?></td>
    <td width="151"><?php
	if ($Document[$dc]['dtd_Status'] == 2) {
	$Qur = "Activo;Inactivo;Caducado;Apagar#2;3;4;5";
	} elseif ($Document[$dc]['dtd_Status'] == 4 || $Document[$dc]['dtd_Status'] == 3 || $Document[$dc]['dtd_Status'] == 5) {
	$Qur = "Activo;inactivo;Caducado#2;3;4";
	} else {
	$Qur = "Activo#2";
	}
	mn_field('hselect',$MDDC,'dtd_Status',$Document[$dc]['dtd_Status'],$Qur,'','False','');?></td>
  </tr>

 <td colspan="6">
	<table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#F4F4F4">
        <tr>
          <td width="30%">&nbsp;</td>
          <td><?php
	if ($MDDC == 'ED') {
	mn_field('button','ED','PRSVDC','Guardar','12','12','False','SUBMIT"
				onClick="document.ClientProperties.action=\'_response/call.php?get=Operative/opv_senderdocumentnew\';
				subform(\'ClientProperties\',\'ACDC\');');
	mn_field('button','ED','PRDCAB','Anular','12','12','False','SUBMIT" onClick="document.getElementById(\'NWDC\').innerHTML=\'\';');
	} ?></td>
          <td>&nbsp;</td>
        </tr>
      </table></td>
  </tr>
</table>
<?php } ?>